package com.huli.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huli.domain.NursingProject;
import com.huli.domain.SysOrganization;
import com.huli.domain.Targetpopulation;
import com.huli.mapper.SysOrganizationMapper;
import com.huli.mapper.TargetpopulationMapper;
import com.huli.service.NursingProjectService;
import com.huli.mapper.NursingProjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
* @author 张庆阳
* @description 针对表【nursing_project(护理项目表)】的数据库操作Service实现
* @createDate 2025-03-13 09:01:15
*/
@Service
public class NursingProjectServiceImpl extends ServiceImpl<NursingProjectMapper, NursingProject>
    implements NursingProjectService{
    @Autowired
    private NursingProjectMapper nursingProjectMapper;
    @Autowired
    private SysOrganizationMapper sysOrganizationMapper;
    @Autowired
    private TargetpopulationMapper targetpopulationMapper;
    //@Override
//    public NursingProject findByOrgName(Integer id) {
//        根据主键来查询
//    NursingProject nursingProject = nursingProjectMapper.selectByid(id);
//    System.err.println(nursingProject);
    //根据查询到的服务id查询到机构名称和地址
//    SysOrganization sysOrganization = sysOrganizationMapper.selectByNameAndAddress(nursingProject.getOrgId());
//    nursingProject.setOrgName(sysOrganization.getOrgName());
//    nursingProject.setAddress(sysOrganization.getAddress());
//    return nursingProject;
//}

    @Override
    @Transactional
    public NursingProject findById(Integer id) {
        NursingProject nursingProject=nursingProjectMapper.findById(id);
        SysOrganization sysOrganization= sysOrganizationMapper.selectByNameAndAddress(nursingProject.getOrgId());
        nursingProject.setOrgName(sysOrganization.getOrgName());
        nursingProject.setAddress(sysOrganization.getAddress());
//        System.err.println(sysOrganization);
//        System.err.println(nursingProject);
        return nursingProject;
    }

    @Override
    @Transactional
    public NursingProject findByid(Integer id) {
        NursingProject nursingProject = nursingProjectMapper.findById(id);
       Targetpopulation targetpopulation=targetpopulationMapper.selectByName(nursingProject.getTargetId());
       nursingProject.setTargetpopulation(targetpopulation.getTargetpopulation());
       return nursingProject;
    }

    @Override
    public NursingProject findByPrice(Integer id) {
      NursingProject nursingProject = nursingProjectMapper.findByPrice(id);
      return nursingProject;
    }

}




